<?php
/**
 * (commands) 亚马逊物流退货报告(1:创建报告id)
 */
namespace App\Console\Commands\SpApi\Report\CreateAndGet;

use App\Crontab\Daily\SpApi\GrabCreateReport;
use App\Models\Amazon\AmazonReportCondition;
use Illuminate\Console\Command;
class FulfillmentCustomerReturns extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sp-report:fulfillment-customer-returns {month=null} {accountId=0}';

    /**
     * The console command description.
     * @var string
     */
    protected $description = 'exe func';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $where = [];
        $accountId = $this->argument('accountId');
        $month = $this->argument('month');
        if($accountId){
            $where['id'] = $accountId;
        }

        if ($month == 'null') {
            //默认取值：上月
            $start_time = date('Y-m-01 00:00:00',strtotime('-1 month'));
            $end_time = date('Y-m-t 23:59:59',strtotime('-1 month'));
        }else{
            //赋值，指定日期参数（月份：2024-01）
            $start_time = date('Y-m-01 00:00:00',strtotime($month));
            $end_time = date('Y-m-t 23:59:59',strtotime($month));
        }

        $reportType = 'GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA';
        $data = [
            'report_type' => $reportType,
            'data_start_time' => getDateFormat($start_time),
            'data_end_time' => getDateFormat($end_time),
        ];

        GrabCreateReport::grab($data,$where);

        $this->info('finish!');
    }
}
